using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;

namespace Pixysoft.Framework.XSchEmA.Comparer
{
    class PrimarykeyComparer : IPrimarykeyCompareResult
    {
        List<PrimaryKeySchema> aSuplusPKs = new List<PrimaryKeySchema>();
        List<PrimaryKeySchema> bSuplusPKs = new List<PrimaryKeySchema>();
        List<KeyValuePair<PrimaryKeySchema, PrimaryKeySchema>> samePrimarykeys =
            new List<KeyValuePair<PrimaryKeySchema, PrimaryKeySchema>>();

        public IPrimarykeyCompareResult Compare(DatabaseSchema aDatabase, DatabaseSchema bDatabase)
        {
            foreach (PrimaryKeySchema aPk in aDatabase.PrimaryKeys)
            {

                PrimaryKeySchema bPk = bDatabase.GetPrimaryKey(aPk.TableName);
                if (bPk != null)
                    samePrimarykeys.Add(new KeyValuePair<PrimaryKeySchema, PrimaryKeySchema>(aPk, bPk));
                else
                    aSuplusPKs.Add(aPk);
            }

            foreach (PrimaryKeySchema bPk in bDatabase.PrimaryKeys)
            {
                PrimaryKeySchema aPk = aDatabase.GetPrimaryKey(bPk.TableName);
                if (aPk == null)
                    bSuplusPKs.Add(bPk);
            }

            return this;
        }

        public List<PrimaryKeySchema> ASuplusPKs
        {
            get { return aSuplusPKs; }
            set { aSuplusPKs = value; }
        }

        public List<PrimaryKeySchema> BSuplusPKs
        {
            get { return bSuplusPKs; }
            set { bSuplusPKs = value; }
        }

        public List<KeyValuePair<PrimaryKeySchema, PrimaryKeySchema>> SamePrimarykeys
        {
            get { return samePrimarykeys; }
            set { samePrimarykeys = value; }
        }
    }
}
